/**
 * import { useConfirm } from '@/composables/useConfirm';
 *
 * const $confirm = useConfirm();
 *
 * $confirm.info('这是一条信息消息');
 * $confirm.success('操作成功完成！');
 * $confirm.warning('这是一条警告消息');
 * $confirm.error('这是一条错误消息');
 */
import { inject } from 'vue';

import type { ConfirmAPI } from '@/components/Confirm/types';

export const useConfirm = (): ConfirmAPI => {
  const confirm = inject<ConfirmAPI>('$confirm');

  if (!confirm) {
    throw new Error('useConfirm must be used within a component that has access to $confirm');
  }

  return confirm;
};
